<template>
  <div>
    <!-- 表单 -->
    <TopFilter ref="form" :cols="3" :list="list" labelWidth="110" @filterChange="formChange"></TopFilter>
    <!-- 表格 -->
    <FilterTable
      ref="table"
      columnsRef="partPartOutboundPartSalesQuoteComponentsQuotationNumber"
      height="auto"
      :columns="columns"
      :datakey="'rows'"
      selectionType="single"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="arr => (this.onChangeColumn = arr)"
    >
    </FilterTable>
    <div class="btnWrap">
      <el-button size="small" @click="cancel">关 闭</el-button>
      <el-button size="small" type="primary" :disabled="saveBtn" @click="determine">确 定</el-button>
    </div>
  </div>
</template>

<script>
import { stockIn, getDealerUser } from '@/api/part/partInventory/partInventory/index.js';
import { dictionary } from '@/utils/dictMixin';
import { SearchSalesQuote } from '@/api/part/partOutbound/partSalesQuote/index.js';
import { arrayObjDeWeight } from '@/utils';

export default {
  name: 'partSalesQuote',
  components: {},
  mixins: [dictionary],
  props: ['orederNo'],
  data() {
    return {
      serviceAdvisorData: [], // 存全部人的信息
      fetchParams: { xhrAbort: true },
      fetchApi: SearchSalesQuote,
      list: this.createList(),
      columns: this.createColumns(),
      onChangeColumn: [], // 单选的数据
      /** 模态框 状态 */
      isShowquotationNumber: false,
      saveBtn: false
      /** 按钮状态 */

      // 表格里

      // 下面

      // 控制操作按钮
    };
  },
  computed: {},
  mounted() {
    this.getEmp();
    this.list.find(x => x.fieldName == 'quoteNo').initialValue = this.orederNo;
    this.fetchParams = Object.assign({}, { quoteNo: this.orederNo }, { xhrAbort: false });
  },
  methods: {
    // 获取员工信息并转义
    async getEmp() {
      const res = await getDealerUser();
      let resData = arrayObjDeWeight(res.data, 'userId');
      this.columns.find(x => x.dataIndex == 'handler').filterItems = this.columns.find(x => x.dataIndex == 'handler').editItems = resData.map(x => ({ value: x.userId + '', text: x.employeeName }));
      // this.columns.find(x => x.dataIndex === 'CREATED_BY').editItems = res.data.map(x => ({ value: x.userId, text: x.employeeName }));
      // this.columns.find(x => x.dataIndex === 'LOCK_USER').editItems = res.data.map(x => ({ value: x.userId, text: x.employeeName }));
    },
    // 确定方法
    determine() {
      this.saveBtn = true;
      if (this.onChangeColumn.length != 1) {
        this.$notify.error({
          title: '错误',
          message: '请选择一条内容'
        });
      } else {
        this.$emit('confirm', this.onChangeColumn);
      }
    },
    // 取消的方法
    cancel() {
      this.$emit('cancel');
    },
    // 配件报价单选择 确定方法
    confirmQuotationNumber() {},
    // 表单的方法
    formChange(val) {
      this.fetchParams = Object.assign({}, val, { xhrAbort: false });
    },
    // 转换数据
    getEmployeeName(userId) {
      const item = this.serviceAdvisorData.find(x => {
        return x.value == userId;
      });
      return item ? item.text : '';
    },
    createList() {
      return [
        {
          type: 'INPUT',
          label: '销售报价单号',
          fieldName: 'quoteNo'
        },
        {
          type: 'SELECT',
          label: '是否完成',
          fieldName: 'isFinished',
          placeholder: '',
          initialValue: '',
          itemList: this.createDictList('1004')
        }
      ];
    },
    createColumns() {
      return [
        {
          title: '序号',
          width: 70,
          dataIndex: 'xuhao',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '销售报价单号',
          minWidth: 150,
          dataIndex: 'salesQuoteNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户名称',
          minWidth: 120,
          dataIndex: 'customerName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '报价日期',
          dataIndex: 'salesQuoteDate',
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '经手人',
          dataIndex: 'handler',
          sorter: true,
          editable: false,
          editType: 'select',
          editItems: [],
          filter: true,
          filterType: 'checkbox',
          filterItems: []
        },
        // {
        //   title: '锁定人',
        //   dataIndex: 'UNIT_NAME'
        // },
        {
          title: '是否完成',
          dataIndex: 'isFinished',
          sorter: true,
          editable: false,
          editType: 'select',
          editItems: this.createDictList(1004),
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList(1004)
        }
      ];
    }
  }
};
</script>

<style scoped lang="less">
.btn-group {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  height: 60px;
}
.btnWrap {
  position: absolute;
  left: 0px;
  bottom: 0px;
  right: 0px;
  z-index: 9;
  border-top: 1px solid rgb(233, 233, 233);
  padding: 10px 20px;
  background: rgb(255, 255, 255);
  text-align: right;
}
</style>
